function onLogout() {
  $.ajax({
    url: '/logout',
    type: 'get',
    success: function(data,status){
      if(status == 'success'){
        /*console.log(data);*/
      }
    },
    error: function(data,err){
      console.log(data);
    }
  });
}

function onCheck(){
  var snum = document.getElementById('getsnum').value;
  hit_load(snum);
  document.getElementById('bingo').style.top = '80px';
}

function table_load() {
  console.log('table load');
  $.ajax({
    url: '/realtime',
    type: 'get',
    success: function(data,status){
      if(status == 'success'){
        console.log(data);
        init_all_table();
        updateTable(data);
        $('.td1').on("click",function(){
          console.log($(this).text());
          /*console.log($(this).offset());*/
          hit_load($(this).text());
          document.getElementById('bingo').style.top = $(this).offset().top+'px';
        })
      }
    },
    error: function(data,err){
      console.log(data);
    }
  });
}

function hit_load(sname){
  $.ajax({
    url: '/hit?snum='+sname,
    type: 'get',
    success: function(data,status){
      if(status == 'success'){
        console.log(data);
        lines = data.split('\n');
        var str = '';
        for(var i in lines){
          items = lines[i].split(',')
          str+='<tr>'
          for(var j in items){
            if(j>0){
              str+='<td>'+items[j]+'</td>'
            }
          }
          str+='</tr>'
        }
        $('#hit-table').html('<tr><td>日期</td><td>模型</td><td>收益1</td><td>收益2</td><td>收益3</td><td>收益4</td><td>收益5</td></tr>');
        $('#hit-table').append(str);
        $('#hit-name').html(sname);
        document.getElementById('bingo').style.display = 'block';
      }
    },
    error: function(data,err){
      console.log(data);
    }
  });
}
function res_load(sname){
  $.ajax({
    url: '/sta_res?name='+sname,
    type: 'get',
    success: function(data,status){
      if(status == 'success'){
        console.log(data);
        lines = data.split('\n')
        var resdata = [];
        resdata[0] = lines[0].split(',');
        resdata[1] = lines[1].split(',');
        resdata[2] = lines[2].split(',');
        resdata[3] = lines[3].split(',');
        resdata[4] = lines[4].split(',');
        console.log(resdata)
        draw_bene_freq(resdata);
        /*draw_ohlc(resdata);*/
        draw_succ_rates(resdata);
      }
    },
    error: function(data,err){
      console.log(data);
    }
  });
}

function draw_bene_freq(resdata){
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('chart0'));
  var slist = [];
  /*slist = data.split('\n');*/
  var date_list = [];
  var today = new Date();
  for(var y=2012;y < 1900 + today.getYear();y++){
    for(var m=1; m <= 12;m++){
      date_list.push(y+'-'+m);
    }
  }
  for(var m=1; m <= 1 + today.getMonth();m++){
    date_list.push((1900+today.getYear())+'-'+m);
  }
  console.log(date_list.length)

  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '收益时间分布'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      }
    },
    toolbox: {
      feature: {
        dataView: {show: true, readOnly: false},
        magicType: {show: true, type: ['line', 'bar']},
        restore: {show: true},
        saveAsImage: {show: true}
      }
    },
    legend: {
      data:['5日最高收益','5日平均收益','出现频次']
    },
    xAxis: [
      {
        type: 'category',
        data: date_list,
        axisPointer: {
          type: 'shadow'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '收益',
      },
      {
        type: 'value',
        name: '频次',
      }
    ],
    series: [
      {
        name:'5日最高收益',
        type:'line',
        data:resdata[1]
      },
      {
        name:'5日平均收益',
        type:'line',
        data:resdata[2]

      },
      {
        name:'出现频次',
        type:'bar',
        yAxisIndex: 1,
        data:resdata[0]
      }
    ]
  };

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
function draw_ohlc(resdata){
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('chart2'));
  var slist = [];
  /*slist = data.split('\n');*/
  var date_list = [];
  var today = new Date();
  for(var y=2012;y < 1900 + today.getYear();y++){
    for(var m=1; m <= 12;m++){
      date_list.push(y+'-'+m);
    }
  }
  for(var m=1; m <= 1 + today.getMonth();m++){
    date_list.push((1900+today.getYear())+'-'+m);
  }
  console.log(date_list.length)

  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '开高低收时间分布'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      }
    },
    toolbox: {
      feature: {
        dataView: {show: true, readOnly: false},
        magicType: {show: true, type: ['line', 'bar']},
        restore: {show: true},
        saveAsImage: {show: true}
      }
    },
    legend: {
      data:['开盘','最高','最低','收盘']
    },
    xAxis: [
      {
        type: 'category',
        data: date_list,
        axisPointer: {
          type: 'shadow'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '收益',
      }
    ],
    series: [
      {
        name:'开盘',
        type:'line',
        data:resdata[2]

      },
      {
        name:'最高',
        type:'line',
        data:resdata[3]
      },
      {
        name:'最低',
        type:'line',
        data:resdata[4]
      },
      {
        name:'收盘',
        type:'line',
        data:resdata[5]

      }
    ]
  };

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

function draw_succ_rates(resdata){
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('chart1'));
  var slist = [];
  /*slist = data.split('\n');*/
  var date_list = [];
  var today = new Date();
  for(var y=2012;y < 1900 + today.getYear();y++){
    for(var m=1; m <= 12;m++){
      date_list.push(y+'-'+m);
    }
  }
  for(var m=1; m <= 1 + today.getMonth();m++){
    date_list.push((1900+today.getYear())+'-'+m);
  }
  console.log(date_list.length)

  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '成功率分布'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      }
    },
    toolbox: {
      feature: {
        dataView: {show: true, readOnly: false},
        magicType: {show: true, type: ['line', 'bar']},
        restore: {show: true},
        saveAsImage: {show: true}
      }
    },
    legend: {
      data:['%8成功率','%5成功率','出现频次']
    },
    xAxis: [
      {
        type: 'category',
        data: date_list,
        axisPointer: {
          type: 'shadow'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '成功率',
      },
      {
        type: 'value',
        name: '频次',
      }
    ],
    series: [
      {
        name:'%8成功率',
        type:'line',
        data:resdata[4]
      },
      {
        name:'%5成功率',
        type:'line',
        data:resdata[3]

      },
      {
        name:'出现频次',
        type:'bar',
        yAxisIndex: 1,
        data:resdata[0]
      }
    ]
  };

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

function draw_succ_rates_iver_anthony(){
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('chart3'));
  var slist = [];
  /*slist = data.split('\n');*/
  var date_list = [];
  var today = new Date();
  for(var y=2012;y < 1900 + today.getYear();y++){
    for(var m=1; m <= 12;m++){
      date_list.push(y+'-'+m);
    }
  }
  for(var m=1; m <= 1 + today.getMonth();m++){
    date_list.push((1900+today.getYear())+'-'+m);
  }
  console.log(date_list.length)

  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '成功率分布 Iverson&Anthony'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      }
    },
    toolbox: {
      feature: {
        dataView: {show: true, readOnly: false},
        magicType: {show: true, type: ['line', 'bar']},
        restore: {show: true},
        saveAsImage: {show: true}
      }
    },
    legend: {
      data:['Iverson%5成功率','Anthony%5成功率','Iverson出现频次','Anthony出现频次']
    },
    xAxis: [
      {
        type: 'category',
        data: date_list,
        axisPointer: {
          type: 'shadow'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '成功率',
      },
      {
        type: 'value',
        name: '频次',
      }
    ],
    series: [
      {
        name:'Iverson%5成功率',
        type:'line',
        data:[0, 0.0, 28.571, 37.5, 20.0, 0.0, 0.0, 75.0, 20.0, 62.5, 33.333, 33.333, 23.529, 66.667, 20.0, 0.0, 16.667, 100.0, 38.889, 45.833, 31.25, 36.0, 28.571, 33.333, 33.333, 21.739, 40.0, 60.0, 50.0, 29.412, 29.63, 42.857, 22.581, 6.25, 25.0, 38.71, 36.364, 42.857, 44.33, 40.678, 52.381, 29.032, 0.0, 44.444, 100.0, 55.556, 40.0, 37.5, 50.0, 0.0, 0.0, 0.0, 40.0, 28.571, 41.176, 42.857, 28.571, 40.0, 39.286, 60.0, 37.5, 50.0, 30.0, 40.0, 42.857]
      },
      {
        name:'Anthony%5成功率',
        type:'line',
        data: [33.333, 20.0, 0.0, 58.333, 0.0, 25.0, 71.429, 30.769, 0.0, 60.0, 0.0, 18.182, 11.111, 16.667, 0.0, 50.0, 18.182, 66.667, 64.286, 25.0, 14.286, 42.857, 50.0, 36.364, 28.571, 41.176, 8.333, 37.5, 37.5, 30.0, 30.0, 22.222, 28.571, 57.143, 63.636, 44.828, 41.667, 33.333, 35.714, 38.0, 44.286, 22.368, 0, 35.065, 44.444, 48.889, 46.667, 30.0, 80.0, 40.909, 41.176, 27.273, 57.143, 10.0, 12.5, 30.769, 42.857, 33.333, 46.154, 0.0, 40.0, 20.0, 50.0, 33.333, 25.0]

      },
      {
        name:'Iverson出现频次',
        type:'bar',
        yAxisIndex: 1,
        data:[0, 2, 7, 8, 5, 3, 3, 4, 5, 8, 3, 6, 17, 6, 10, 4, 12, 1, 18, 24, 32, 25, 21, 15, 18, 23, 15, 5, 4, 17, 27, 28, 31, 16, 20, 31, 11, 14, 97, 118, 210, 155, 1, 9, 1, 9, 65, 32, 2, 1, 1, 6, 10, 21, 17, 7, 7, 10, 28, 10, 8, 8, 10, 25, 7]
      },
      {
        name:'Anthony出现频次',
        type:'bar',
        yAxisIndex: 1,
        data:[3, 5, 4, 12, 5, 4, 7, 13, 2, 5, 4, 11, 9, 6, 3, 2, 11, 3, 14, 8, 14, 14, 10, 11, 7, 17, 12, 8, 8, 10, 10, 9, 7, 7, 11, 29, 12, 12, 28, 50, 70, 76, 0, 77, 63, 45, 30, 30, 15, 22, 17, 11, 7, 20, 8, 13, 7, 3, 13, 10, 5, 5, 8, 6, 4]
      }
    ]
  };

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
window.onload = init();
function init(){
  res_load('kobe_sta');
}

